package com.kehao.leetcode.basic.string;

import org.junit.Test;

/**
 * 字符串中的第一个唯一字符
 */
public class StringSolution3 {
    public int firstUniqChar(String s) {
        char[] charArray = s.toCharArray();
        for (int i = 0; i < charArray.length; i++){
            int k = 0;int j = charArray.length-1;
            for (; k < charArray.length; k++){
                if(charArray[i]==charArray[k]){
                    break;
                }
            }
            for (; j >=0 ; j--) {
                if(charArray[i]==charArray[j]){
                    break;
                }
            }
            if(k==j){
                return k;
            }
        }
        return -1;
    }

    @Test
    public void myTest(){
        System.out.println(firstUniqChar("loveleetcode"));
    }
}
